{layout name="layout"}
{include file="public/nav"}
<div class="container-fluid" style="text-align: center">
    <h1>修改密码</h1>
</div>

<div class="container" style="text-align: center; ">
        <label for="oldPass">输入旧密码</label>
        <input class="form-control" id="oldPass"  name="oldpass" type="password" value="">

        <br><br>
        <label for="newPass1">输入新密码</label>
        <input class="form-control" id="newPass1" name="newpass1" type="password" value="">

        <br><br>
        <label for="newPass2">再次输入新密码</label>
        <input class="form-control" id="newPass2" name="newpass2" type="password" value="">

        <br><br>
        <button id="changePass" class="btn btn-danger pull-right"> 修改密码 </button>
<!--    <h1 style="color: crimson"> 修改密码功能暂未开启，请联系管理员操作 </h1>-->
</div>

<script>
    /*x修改密码*/
    $("#changePass").click(function () {
        let oldPass = document.getElementById("oldPass").value
        let newPass1 = document.getElementById("newPass1").value
        let newPass2 = document.getElementById("newPass2").value

        if(newPass1 === '' || newPass2 === '' || oldPass === ''){
            alert("请填写完整信息")
        }
        else if(newPass1 !== newPass2){
            alert("两次新密码不一致")
        }else{
            $.ajax({
                type: "POST",
                url: "/admin/changePass",
                datatype: "JSON",
                data: {
                    'oldPass'  :  oldPass,
                    'newPass1' :  newPass1,
                    'newPass2' :  newPass2
                },
                success:function (data) {
                    if(data === 1){
                        alert("修改密码成功，请牢记密码:"+newPass2)
                        // console.log(data);
                    }else{
                        alert("修改密码失败")
                    }
                    // console.log(data);
                },
                error:function (error) {
                    alert("修改密码失败")
                    console.log(error);
                }
            })
        }
    })
</script>